/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package db.dbTables;

import core.objects.Author;
import core.objects.BaseObject;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

public class AuthorTable extends AbstractDBTable {

    public static final String COLUMN_ID = "author_id";
    public static final String COLUMN_BIRTH_DAY = "birthday";
    public static final String COLUMN_DEATH_DAY = "deathday";

    final public DbColumn id = new DbColumn(COLUMN_ID, Types.INTEGER, 11, false, this);
    final public DbColumn name = new DbColumn(COLUMN_NAME, Types.VARCHAR, 120, false, this);
    final public DbColumn birthday = new DbColumn(COLUMN_BIRTH_DAY, Types.DATE, -1, true, this);
    final public DbColumn deathday = new DbColumn(COLUMN_DEATH_DAY, Types.DATE, -1, true, this);

    public AuthorTable() {
        super("author");
        setIDColumn(id);
    }

    @Override
    public List<DbColumn> getDbColumns() {
        List<DbColumn> list = new ArrayList<DbColumn>();
        list.add(id);
        list.add(name);
        list.add(birthday);
        list.add(deathday);
        return list;
    }

    @Override
    public BaseObject convertSqlTableToBaseObject(ResultSet resultSet) {
        int id = 0;
        String name = null;
        Date birthday = null, deathday = null;
        try {
            id = resultSet.getInt(COLUMN_ID);
            name = resultSet.getString(COLUMN_NAME);
            birthday = resultSet.getDate(COLUMN_BIRTH_DAY);
            deathday = resultSet.getDate(COLUMN_DEATH_DAY);

        } catch (SQLException ex) {
            Logger.getLogger(AuthorTable.class.getName()).log(Level.SEVERE, null, ex);
        }
        return new Author(id, name, birthday, deathday);
    }
}
